package leetcode.code1326;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	int inf = (int) 1e5;

	public int minTaps(int n, int[] ranges) {
		int[] dp = new int[n + 1];
		Arrays.fill(dp, inf);
		dp[0] = 0;
		for (int i = 0; i <= n; i++) {
			int range = ranges[i];
			int l = i - range, r = i + range;
			int min = inf;
			for (int j = Math.max(l, 0); j <= Math.min(r, n); j++) {
				min = Math.min(min, dp[j] + 1);
			}
			dp[Math.min(r, n)] = Math.min(dp[Math.min(r, n)], min);
		}
		return dp[n] == inf ? -1 : dp[n];
	}

	@Override
	public void debug4() {
		H.compare(1, this.minTaps(5, H.str2array3("[3,4,1,1,0,0]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
